# coding: utf-8
from sqlalchemy import Column, Integer, BLOB, LargeBinary
from sqlalchemy.dialects.mysql import VARCHAR

from app import db
from app import ma


# Base = declarative_base()
# metadata = Base.metadata


class DepartmentInfo(db.Model):
    __tablename__ = 'department_info'
    __table_args__ = {'comment': '部门信息'}

    id = Column(Integer, primary_key=True, comment='部门编号')
    name = Column(VARCHAR(50), nullable=False, comment='部门名称')


class EmployeeInfo(db.Model):
    __tablename__ = 'employee_info'
    __table_args__ = {'comment': '员工信息'}

    id = Column(Integer, primary_key=True, comment='员工编号')
    username = Column(VARCHAR(50), nullable=False, comment='账号')
    password = Column(VARCHAR(50), nullable=False, comment='密码')
    name = Column(VARCHAR(50), nullable=False, comment='姓名')
    gender = Column(VARCHAR(10), nullable=False, comment='性别（男/女）')
    department_id = Column(Integer, nullable=False, comment='部门编号')
    position_id = Column(Integer, nullable=False, comment='职位编号')
    contact_number = Column(VARCHAR(20), nullable=False, comment='联系电话')
    role_id = Column(Integer, nullable=False, comment='角色编号（1: 管理员，2: 用户)')
    photo = Column(VARCHAR(255), nullable=True, comment='员工照片')


class PositionInfo(db.Model):
    __tablename__ = 'position_info'
    __table_args__ = {'comment': '职位信息'}

    id = Column(Integer, primary_key=True, comment='职位编号')
    name = Column(VARCHAR(50), nullable=False, comment='职位名称')


class RoleInfo(db.Model):
    __tablename__ = 'role_info'
    __table_args__ = {'comment': '角色信息'}

    id = Column(Integer, primary_key=True, comment='角色编号')
    NAME = Column(VARCHAR(50), nullable=False, comment='角色名称')


class DepartmentInfoSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = DepartmentInfo


class PositionInfoSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = PositionInfo


class EmployeeInfoSchema(ma.SQLAlchemyAutoSchema):
    department = ma.Nested(DepartmentInfoSchema)
    position = ma.Nested(PositionInfoSchema)

    class Meta:
        model = EmployeeInfo


class RoleInfoSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = RoleInfo
